package com.hutao.medical.service.impl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.medical.common.config.ConfigProperties;
import com.hutao.medical.common.config.ErrorType;
import com.hutao.medical.common.config.FunctionType;
import com.hutao.medical.common.util.DateUtil;
import com.hutao.medical.common.util.DiseaseValidateUtil;
import com.hutao.medical.common.util.JsonUtils;
import com.hutao.medical.common.util.StringUtil;
import com.hutao.medical.constant.Constant;
import com.hutao.medical.constant.ModifyConstant;
import com.hutao.medical.dataSource.TargetDataSource;
import com.hutao.medical.mapper.MedicalErrorMapper;
import com.hutao.medical.mapper.MedicalModifyMapper;
import com.hutao.medical.mapper.audit.MedicalRecordAuditMapper;
import com.hutao.medical.mapper.borrow.HospitalNoteMapper;
import com.hutao.medical.mapper.borrow.MedicalFunctionMapper;
import com.hutao.medical.pojo.MedicalModify;
import com.hutao.medical.pojo.audit.AuditDetail;
import com.hutao.medical.pojo.audit.AuditErrorMsg;
import com.hutao.medical.pojo.borrow.HospitalNote;
import com.hutao.medical.pojo.borrow.MedicalFunction;
import com.hutao.medical.pojo.dto.MedicalSearchQuery;
import com.hutao.medical.pojo.model.HospitalVisitBasicInfo;
import com.hutao.medical.pojo.model.HospitalVisitCureInfo;
import com.hutao.medical.pojo.model.HospitalVisitCureWorker;
import com.hutao.medical.pojo.model.HospitalVisitDiagAccordRecord;
import com.hutao.medical.pojo.model.HospitalVisitDiseaseDiagInfo;
import com.hutao.medical.pojo.model.HospitalVisitDiseaseDiagRecord;
import com.hutao.medical.query.AuditError;
import com.hutao.medical.query.AuditQuery;
import com.hutao.medical.query.MedModifyVo;
import com.hutao.medical.query.MedRecordQuery;
import com.hutao.medical.service.MedRecordAuditService;

@Service
public class MedRecordAuditServiceImpl implements MedRecordAuditService {

	@Autowired
	private MedicalRecordAuditMapper medicalRecordAuditMapper;
	@Autowired
	private ConfigProperties configProperties;

	@Autowired
	private MedicalFunctionMapper medicalFunctionMapper;
	@Autowired
	private HospitalNoteMapper hospitalNoteMapper;
	@Autowired
	private MedicalModifyMapper medicalModifyMapper;

	@Autowired
	private MedicalErrorMapper medicalErrorMapper;

	@Transactional(readOnly = true)
	@TargetDataSource(name = "ds1")
	@Override
	public List<Map<String, Object>> selectMedicalRecordRetrievaList(MedicalSearchQuery medicalSearchQuery) {
		return medicalRecordAuditMapper.selectMedicalRecordRetrievaList(medicalSearchQuery);
	}

	@Transactional(readOnly = true)
	@TargetDataSource(name = "ds1")
	@Override
	public int selectMedicalRecordRetrievaCount(MedicalSearchQuery medicalSearchQuery) {
		return medicalRecordAuditMapper.selectMedicalRecordRetrievaCount(medicalSearchQuery);
	}

	/**
	 * 查询自动审核信息
	 * 
	 * @param auditQuery
	 * @return
	 * @throws ParseException
	 */
	@SuppressWarnings("unchecked")
	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void getAutoAuditList(List<String> firstGuidList) throws ParseException {
		// 查询数据为空直接返回
		if (CollectionUtils.isEmpty(firstGuidList)) {
			return;
		}

		for (String firstGuid : firstGuidList) {
			// 本地读取首页结构化json文件
			String filePath = configProperties.getServer().getHospitalNoteJsonLocalPath()
					+ StringUtil.getLocalPath(firstGuid);
			String fileName = firstGuid + ".json";
			Map<String, Object> jsonMap = readLineFile(filePath, fileName);
			if (MapUtils.isEmpty(jsonMap)) {
				continue;
			}

			Map<String, Object> basicInfoMap = (Map<String, Object>) jsonMap.get("basicInfo");
			// 基本信息为空怎么处理
			if (MapUtils.isEmpty(basicInfoMap)) {
				continue;
			}

			// 根据firstGuid读取HospitalNote如果不存在新增,存在更新
			HospitalNote hospitalNote = hospitalNoteMapper.getHospitalNoteByFirstGuid(firstGuid);
			if (hospitalNote == null) {
				hospitalNote = this.appendHospitalNote(firstGuid, basicInfoMap);
				hospitalNoteMapper.insertSelective(hospitalNote);
			} else {
				hospitalNote = this.appendUpdateHospitalNote(firstGuid, basicInfoMap, hospitalNote);
				hospitalNoteMapper.updateByPrimaryKeySelective(hospitalNote);
			}

			// 根据firstGuid和FunctionType查询MedicalFunction如果存在直接返回不存在新增
			MedicalFunction medicalFunction = null;
			if (medicalFunctionMapper.isExistMedFunctionByFirstGuidAndFunType(firstGuid,
					FunctionType.MEDICAL_MODIFY) > 0) {
				medicalFunction = medicalFunctionMapper.getMediFunctionIdFirstGuidAndFunType(firstGuid,
						FunctionType.MEDICAL_MODIFY);
			} else {
				medicalFunction = new MedicalFunction();
				medicalFunction.setCreateTime(new Date());
				medicalFunction.setFirstGuid(firstGuid);
				medicalFunction.setStatus(1);
				medicalFunction.setFunctionTypeId(FunctionType.MEDICAL_MODIFY);
				medicalFunctionMapper.insertSelective(medicalFunction);
			}

			// 基本信息
			HospitalVisitBasicInfo hospitalVisitBasicInfo = JsonUtils.jsonToPojo(JsonUtils.objectToJson(basicInfoMap),
					HospitalVisitBasicInfo.class);

			BigDecimal age = hospitalVisitBasicInfo.getAge();
			if (age == null || age.intValue() < 0 || age.intValue() > 150) {
				this.addMedicalModify(ModifyConstant.NULL_AGE_OR_RANGE_WIDTH, medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_AGE_OR_RANGE_WIDTH, "修改年龄为:" + age.intValue(),
						medicalFunction.getId());
			}

			String sexName = hospitalVisitBasicInfo.getSexName();

			String outHospitalTypeName = hospitalVisitBasicInfo.getOutHospitalTypeName();
			String autopsyCode = hospitalVisitBasicInfo.getAutopsyCode();
			if (StringUtils.isNotEmpty(autopsyCode)
					&& (StringUtils.isNotEmpty(outHospitalTypeName) && !"死亡".equals(outHospitalTypeName))) {
				this.addMedicalModify(ModifyConstant.DEAD_BODY_CHECK_OUTTYPE_NOT_DEAD, medicalFunction.getId());

			} else {
				this.updateMedicalModify(ModifyConstant.DEAD_BODY_CHECK_OUTTYPE_NOT_DEAD,
						"修改出院方式为:" + outHospitalTypeName, medicalFunction.getId());
			}

			// 入院日期
			Date inHospitalDate = hospitalVisitBasicInfo.getInHospitalDateTime();
			// 出院日期
			Date outHospitalDate = hospitalVisitBasicInfo.getOutHospitalDateTime();
			// 确诊时间
			Date diagConfirmedDate = hospitalVisitBasicInfo.getDiagConfirmedDateTime();
			// 付费方式
			String medicalPayTypeName = hospitalVisitBasicInfo.getMedicalPayTypeName();
			// 是否为军事训练伤
			String militaryTrainingInjuryName = hospitalVisitBasicInfo.getMilitaryTrainingInjuryName();
			if (StringUtils.isEmpty(medicalPayTypeName)) {
				this.addMedicalModify(ModifyConstant.NULL_PAY_STYLE, medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_PAY_STYLE, "添加付费方式为:" + medicalPayTypeName,
						medicalFunction.getId());

				if (medicalPayTypeName.equals("军队医改") && StringUtils.isEmpty(militaryTrainingInjuryName)) {
					this.addMedicalModify(ModifyConstant.WHETHER_MILITARY_TRAINING_INJURY, medicalFunction.getId());
				} else {
					this.updateMedicalModify(ModifyConstant.WHETHER_MILITARY_TRAINING_INJURY,
							"付费方式为军队医改填写军事训练伤为:" + militaryTrainingInjuryName, medicalFunction.getId());
				}
			}

			// 确诊时间为空
			if (!diagConfirmTimeIsNull(diagConfirmedDate, inHospitalDate, outHospitalDate)) {
				this.addMedicalModify(ModifyConstant.NULL_DIAG_CONFIRM_TIME_CODE, medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_DIAG_CONFIRM_TIME_CODE,
						"添加确诊时间为:" + DateUtil.dateToStr(diagConfirmedDate, "yyyy-MM-dd HH:mm:ss"),
						medicalFunction.getId());
			}

			// 出院方式
			// String outHospitalTypeName =
			// hospitalVisitBasicInfo.getOutHospitalTypeName();

			// 疾病诊断
			Map<String, Object> diseaseDiagInfoMap = (Map<String, Object>) jsonMap.get("diseaseDiagInfo");
			if (MapUtils.isEmpty(diseaseDiagInfoMap)) {
				continue;
			}

			HospitalVisitDiseaseDiagInfo hospitalVisitDiseaseDiagInfo = JsonUtils
					.jsonToPojo(JsonUtils.objectToJson(diseaseDiagInfoMap), HospitalVisitDiseaseDiagInfo.class);
			List<HospitalVisitDiseaseDiagRecord> diseaseDiagRecordList = hospitalVisitDiseaseDiagInfo
					.getDiseaseDiagRecords();
			int mianDiagCount = 0;
			int pathologicDiagnosisCount = 0;
			List<String> mainDiagnosisDescList = new ArrayList<>();
			List<String> otherDiagnosisDescList = new ArrayList<>();
			if (CollectionUtils.isEmpty(diseaseDiagRecordList)) {
				this.addMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS, medicalFunction.getId());
				this.addMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS_RESULT, medicalFunction.getId());
				this.addMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS_CODE, medicalFunction.getId());
				this.addMedicalModify(ModifyConstant.NULL_IN_HOSPITAL_DIAGNOSIS_CODE, medicalFunction.getId());
			} else {
				int errorOtherDiagCodeCount = 0;
				int diagCodeCount=0;
				for (HospitalVisitDiseaseDiagRecord hospitalVisitDiseaseDiagRecord : diseaseDiagRecordList) {
					String diagTypeCode = hospitalVisitDiseaseDiagRecord.getDiagTypeCode();
					String diseaseDiagCode = hospitalVisitDiseaseDiagRecord.getDiseaseDiagCode();
					String diseaseDiagOriginalDesc = hospitalVisitDiseaseDiagRecord.getDiseaseDiagOriginalDesc();
					String diseaseDiagName = hospitalVisitDiseaseDiagRecord.getDiseaseDiagName();
					if (StringUtils.isEmpty(diagTypeCode)) {
						
						continue;
					}
					
					if(StringUtils.isEmpty(diseaseDiagCode)){
						diagCodeCount++;
					}
					
					if (diagTypeCode.equals("1")) {
						if (StringUtils.isNotEmpty(sexName)) {

							if ("男".equals(sexName)) {
								if (!DiseaseValidateUtil.validateManClinicDiagCode(diseaseDiagCode)) {
									this.addMedicalModify(ModifyConstant.MAN_CLINIC_DIAG_CODE_NOT,
											medicalFunction.getId());
								} else {
									this.updateMedicalModify(ModifyConstant.MAN_CLINIC_DIAG_CODE_NOT,
											"修改门诊诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
											medicalFunction.getId());
								}
							}

							if ("女".equals(sexName)) {
								if (!DiseaseValidateUtil.validateFemalClinicDiagCode(diseaseDiagCode)) {
									this.addMedicalModify(ModifyConstant.FEMAL_CLINIC_DIAG_CODE_NOT,
											medicalFunction.getId());
								} else {
									this.updateMedicalModify(ModifyConstant.FEMAL_CLINIC_DIAG_CODE_NOT,
											"修改门诊诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
											medicalFunction.getId());
								}
							}
						}
					}

					if (diagTypeCode.equals("3")) {
						// 主要诊断不能以B95-B97、O06、Z80-Z99、T32、M99开头为主要诊断编码
						if (!DiseaseValidateUtil.validateMainDiag(diseaseDiagCode)) {
							this.addMedicalModify(ModifyConstant.MAIN_DIAG_CODE_NOT_CONTAIN, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.MAIN_DIAG_CODE_NOT_CONTAIN,
									"修改主要诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode, medicalFunction.getId());
						}
						// 主要诊断以T80-T88开头为主要诊断编码可能隐含医疗风险
						if (!DiseaseValidateUtil.validateRaiseMainDiag(diseaseDiagCode)) {
							this.addMedicalModify(ModifyConstant.MAIN_DIAG_CODE_HAS_RAISE, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.MAIN_DIAG_CODE_HAS_RAISE,
									"修改主要诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode, medicalFunction.getId());
						}

						// 12岁以下儿童不能以有男性女性生殖疾病和分娩相关的编码为主要诊断编码
						if (age != null && age.intValue() < 12) {
							if (!DiseaseValidateUtil.validateChildDisease(diseaseDiagCode,
									DiseaseValidateUtil.CHILD_NOT_CONTAIN_DIAG_CODE)) {
								this.addMedicalModify(ModifyConstant.CHILD_NOT_CONTAIM_DIAG_CODE,
										medicalFunction.getId());
							} else {
								this.updateMedicalModify(ModifyConstant.CHILD_NOT_CONTAIM_DIAG_CODE,
										"修改主要诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
										medicalFunction.getId());
							}
						}

						if (StringUtils.isNotEmpty(sexName)) {

							if ("男".equals(sexName)) {
								if (!DiseaseValidateUtil.validateManMainDiag(diseaseDiagCode)) {
									this.addMedicalModify(ModifyConstant.MAN_MAIN_DIAG_NOT_CONTAIM_DIAG_CODE,
											medicalFunction.getId());
								} else {
									this.updateMedicalModify(ModifyConstant.MAN_MAIN_DIAG_NOT_CONTAIM_DIAG_CODE,
											"修改主要诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
											medicalFunction.getId());
								}
							}

							if ("女".equals(sexName)) {
								if (!DiseaseValidateUtil.validateFemalMainDiag(diseaseDiagCode)) {
									this.addMedicalModify(ModifyConstant.FEMALE_MAIN_DIAG_NOT_CONTAIM_DIAG_CODE,
											medicalFunction.getId());
								} else {
									this.updateMedicalModify(ModifyConstant.FEMALE_MAIN_DIAG_NOT_CONTAIM_DIAG_CODE,
											"修改主要诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
											medicalFunction.getId());
								}
							}
						}

						mainDiagnosisDescList.add(diseaseDiagOriginalDesc);

						// 疾病描述
//						if (StringUtils.isEmpty(diseaseDiagOriginalDesc)) {
//
//							this.addMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS, medicalFunction.getId());
//						} else {
//							this.updateMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS,
//									"添加第一出院诊断名称为:" + diseaseDiagOriginalDesc, medicalFunction.getId());
//						}

						// 治疗结果
						// if (StringUtils.isEmpty(treatResultName)) {
						// this.addMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS_RESULT,
						// medicalFunction.getId());
						// } else {
						// this.updateMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS_RESULT,
						// "添加第一出院诊断治疗结果为:" + treatResultName,
						// medicalFunction.getId());
						// // 出院方式
						// if
						// (!treatemnetResutIsMatchOutTypeName(outHospitalTypeName,
						// treatResultName)) {
						// this.addMedicalModify(ModifyConstant.RESULT_TREAMENT_NOTCONSISTENT_DISCHARGE_DATA,
						// medicalFunction.getId());
						// } else {
						// this.updateMedicalModify(ModifyConstant.RESULT_TREAMENT_NOTCONSISTENT_DISCHARGE_DATA,
						// "修改该病例治疗结果为:" + treatResultName,
						// medicalFunction.getId());
						// }
						// }

						// 疾病编码
						// if (StringUtils.isEmpty(diseaseDiagName)) {
						// this.addMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS_CODE,
						// medicalFunction.getId());
						// } else {
						// this.updateMedicalModify(ModifyConstant.NULL_MAIN_DIAGNOSIS_CODE,
						// "添加第一出院诊断编码为:" + diseaseDiagName,
						// medicalFunction.getId());
						// }

						mianDiagCount++;
					}
//					// 入院诊断
//					if (diagTypeCode.equals("2")) {
//						// 疾病编码
//						if (StringUtils.isEmpty(diseaseDiagName)) {
//							this.addMedicalModify(ModifyConstant.NULL_IN_HOSPITAL_DIAGNOSIS_CODE,
//									medicalFunction.getId());
//						} else {
//							this.updateMedicalModify(ModifyConstant.NULL_IN_HOSPITAL_DIAGNOSIS_CODE,
//									"添加第一入院诊断编码为:" + diseaseDiagName, medicalFunction.getId());
//						}
//					}

					// 病理诊断
					if (diagTypeCode.equals("8")) {
						pathologicDiagnosisCount++;
					}

					// 其他诊断
					if (diagTypeCode.equals("A")) {

						if (StringUtils.isNotEmpty(sexName)) {

							if ("男".equals(sexName)) {
								if (!DiseaseValidateUtil.validateManOtherDiagCode(diseaseDiagCode)) {
									errorOtherDiagCodeCount++;
									this.addMedicalModify(ModifyConstant.MAN_MIAN_OTHER_DIAG_CODE_NOT,
											medicalFunction.getId());
								} else {
									this.updateMedicalModify(ModifyConstant.MAN_MIAN_OTHER_DIAG_CODE_NOT,
											"修改其他诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
											medicalFunction.getId());
								}
							}

							if ("女".equals(sexName)) {
								if (!DiseaseValidateUtil.validateFemalOtherDiagCode(diseaseDiagCode)) {
									errorOtherDiagCodeCount++;
									this.addMedicalModify(ModifyConstant.FEMAL_MIAN_OTHER_DIAG_CODE_NOT,
											medicalFunction.getId());
								} else {
									this.updateMedicalModify(ModifyConstant.FEMAL_MIAN_OTHER_DIAG_CODE_NOT,
											"修改其他诊断编码为:" + diseaseDiagName + "-" + diseaseDiagCode,
											medicalFunction.getId());
								}
							}
						}

						otherDiagnosisDescList.add(diseaseDiagOriginalDesc);
					}

				}
				
				
				// 入院诊断
				if (diagCodeCount>0) {
					// 疾病编码
				
						this.addMedicalModify(ModifyConstant.NULL_IN_HOSPITAL_DIAGNOSIS_CODE,
								medicalFunction.getId());
					 
				}else{
					this.updateMedicalModify(ModifyConstant.NULL_IN_HOSPITAL_DIAGNOSIS_CODE,
							"添加诊断编码:", medicalFunction.getId());
				}
				
				
				// 其他诊断编码错误
				if (errorOtherDiagCodeCount > 0) {

					if (StringUtils.isNotEmpty(sexName)) {

						if ("男".equals(sexName)) {

							this.addMedicalModify(ModifyConstant.MAN_MIAN_OTHER_DIAG_CODE_NOT, medicalFunction.getId());

						}

						if ("女".equals(sexName)) {

							this.addMedicalModify(ModifyConstant.FEMAL_MIAN_OTHER_DIAG_CODE_NOT,
									medicalFunction.getId());

						}

					} else {
						if ("男".equals(sexName)) {

							this.updateMedicalModify(ModifyConstant.MAN_MIAN_OTHER_DIAG_CODE_NOT, "修改其他诊断编码正确",
									medicalFunction.getId());

						}

						if ("女".equals(sexName)) {

							this.updateMedicalModify(ModifyConstant.FEMAL_MIAN_OTHER_DIAG_CODE_NOT, "修改其他诊断编码正确",
									medicalFunction.getId());

						}

					}
				}

				// 主要诊断编码重复
				if (CollectionUtils.isNotEmpty(mainDiagnosisDescList)) {
					if (mainDiagnosisDescList.size() > 1) {
						this.addMedicalModify(ModifyConstant.MAIN_DIAGNOSIS_REPEAT, medicalFunction.getId());
					} else {
						this.updateMedicalModify(ModifyConstant.MAIN_DIAGNOSIS_REPEAT, "去除重复的主要诊断名称",
								medicalFunction.getId());

						if (otherDiagnosisDescList.containsAll(mainDiagnosisDescList)) {
							this.addMedicalModify(ModifyConstant.MAIN_DIAGNOSIS_OTHER_DIAGNOSIS_REPEAT,
									medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.MAIN_DIAGNOSIS_OTHER_DIAGNOSIS_REPEAT,
									"去除重复的其他诊断名称", medicalFunction.getId());
						}
					}
				}

			}

			boolean operationFlag = true;
			// 手术
			Map<String, Object> operateInfoMap = (Map<String, Object>) jsonMap.get("operateInfo");

			System.out.println(operateInfoMap);
			if (MapUtils.isEmpty(operateInfoMap)) {
				operationFlag = false;
			} else {
				/*
				 * HospitalVisitOperateInfo hospitalVisitOperateInfo =
				 * JsonUtils.jsonToPojo(JsonUtils.objectToJson(operateInfoMap),
				 * HospitalVisitOperateInfo.class);
				 * 
				 * if(hospitalVisitOperateInfo!=null){
				 * List<HospitalVisitOperateRecord> operateRecordList=
				 * hospitalVisitOperateInfo.getOperateRecords();
				 * if(CollectionUtils.isEmpty(operateRecordList)){ operationFlag
				 * = false; } }else{ operationFlag = false; }
				 */

			}

			// 治疗结果
			Map<String, Object> cureInfoMap = (Map<String, Object>) jsonMap.get("cureInfo");
			// 基本信息为空怎么处理
			if (MapUtils.isEmpty(cureInfoMap)) {
				continue;
			}

			HospitalVisitCureInfo hospitalVisitCureInfo = JsonUtils.jsonToPojo(JsonUtils.objectToJson(cureInfoMap),
					HospitalVisitCureInfo.class);
			// 质控日期
			Date qualityControlDate = hospitalVisitCureInfo.getQualityControlDateTime();
			if (!qualityControlDateIsNull(qualityControlDate, inHospitalDate)) {

				this.addMedicalModify(ModifyConstant.NULL_QUALITY_OR_LOWER_THAN_INHOSPITAL_TIME,
						medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_QUALITY_OR_LOWER_THAN_INHOSPITAL_TIME,
						"添加确诊时间为:" + DateUtil.dateToStr(qualityControlDate, "yyyy-MM-dd HH:mm:ss"),
						medicalFunction.getId());
			}

			// HIV
			String hivAbResultName = hospitalVisitCureInfo.getHivAbResultName();
			if (StringUtils.isEmpty(hivAbResultName)) {

				this.addMedicalModify(ModifyConstant.NULL_HIV, medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_HIV, "患者HIV选择为:" + hivAbResultName,
						medicalFunction.getId());
			}

			// HCV
			String hcvAbResultName = hospitalVisitCureInfo.getHcvAbResultName();
			if (StringUtils.isEmpty(hcvAbResultName)) {

				this.addMedicalModify(ModifyConstant.NULL_HCV, medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_HCV, "患者HCV选择为:" + hcvAbResultName,
						medicalFunction.getId());
			}

			// NULL_HBSAG
			String hbsAgeResultName = hospitalVisitCureInfo.getHbsAgeResultName();
			if (StringUtils.isEmpty(hbsAgeResultName)) {

				this.addMedicalModify(ModifyConstant.NULL_HBSAG, medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_HBSAG, "患者HBSAG选择为:" + hbsAgeResultName,
						medicalFunction.getId());
			}

			// 病案质量
			String medicalRecordQualityName = hospitalVisitCureInfo.getMedicalRecordQualityName();
			if (!qualityRecordNameIsNull(medicalRecordQualityName)) {

				this.addMedicalModify(ModifyConstant.NULL_MEDICAL_RECORD_QUALITY_OR_NOT_IN＿ABC,
						medicalFunction.getId());
			} else {
				this.updateMedicalModify(ModifyConstant.NULL_MEDICAL_RECORD_QUALITY_OR_NOT_IN＿ABC,
						"添加质控质量为:" + medicalRecordQualityName, medicalFunction.getId());
			}

			List<HospitalVisitCureWorker> cureWorker = hospitalVisitCureInfo.getCureWorkers();
			if (CollectionUtils.isEmpty(cureWorker)) {

			} else {
				for (HospitalVisitCureWorker hospitalVisitCureWorker : cureWorker) {
					String professionTitleName = hospitalVisitCureWorker.getProfessionTitleName();
					String medicalWorkerName = hospitalVisitCureWorker.getMedicalWorkerName();
					// 科主任
					if(StringUtils.isEmpty(professionTitleName)){
						continue;
					}
					if (professionTitleName.equals("科主任")) {
						if (StringUtils.isEmpty(medicalWorkerName)) {
							this.addMedicalModify(ModifyConstant.NULL_HEAD_OF_DEPARTMENT, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NULL_HEAD_OF_DEPARTMENT,
									"添加科主任为:" + medicalWorkerName, medicalFunction.getId());
						}
					}

					// 主治医师
					if (professionTitleName.equals("主治医师")) {
						if (StringUtils.isEmpty(medicalWorkerName)) {
							this.addMedicalModify(ModifyConstant.NULL_ATTENDING_DOCTOR, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NULL_ATTENDING_DOCTOR,
									"添加主治医师为:" + medicalWorkerName, medicalFunction.getId());
						}
					}

					// 质控医师
					if (professionTitleName.equals("质控医师")) {
						if (StringUtils.isEmpty(medicalWorkerName)) {
							this.addMedicalModify(ModifyConstant.NULL_QUALITY_CONTROL_PHYSICIAN,
									medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NULL_QUALITY_CONTROL_PHYSICIAN,
									"添加质控医师为:" + medicalWorkerName, medicalFunction.getId());
						}
					}

					// 质控护士
					if (professionTitleName.equals("质控护士")) {
						if (StringUtils.isEmpty(medicalWorkerName)) {
							this.addMedicalModify(ModifyConstant.NULL_QUALITY_CONTROL_NURSE, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NULL_QUALITY_CONTROL_NURSE,
									"添加质控护士为:" + medicalWorkerName, medicalFunction.getId());
						}
					}

					// 住院医师
					if (professionTitleName.equals("住院医师")) {
						if (StringUtils.isEmpty(medicalWorkerName)) {
							this.addMedicalModify(ModifyConstant.NULL_DOCTOR_OF_TREATMENT, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NULL_DOCTOR_OF_TREATMENT,
									"添加经治医师为:" + medicalWorkerName, medicalFunction.getId());
						}
					}

					// 编码员
					if (professionTitleName.equals("编码员")) {
						if (StringUtils.isEmpty(medicalWorkerName)) {
							this.addMedicalModify(ModifyConstant.NULL_CODER, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NULL_CODER, "添加编码员为:" + medicalWorkerName,
									medicalFunction.getId());
						}
					}

				}
			}

			List<HospitalVisitDiagAccordRecord> diagAccordRecords = hospitalVisitCureInfo.getDiagAccordRecords();
			if (CollectionUtils.isEmpty(diagAccordRecords)) {
				this.addMedicalModify(ModifyConstant.NO_OUTPATIENT_DISCHARGE_DIAGNOSIS_OR_ISUNDO,
						medicalFunction.getId());
				this.addMedicalModify(ModifyConstant.NO_HOSPITAL_DISCHARGE_DIAGNOSIS_OR_ISUNDO,
						medicalFunction.getId());
			} else {
				for (HospitalVisitDiagAccordRecord hospitalVisitDiagAccordRecord : diagAccordRecords) {
					String diagCompareName = hospitalVisitDiagAccordRecord.getDiagCompareName();
					String diagAccordName = hospitalVisitDiagAccordRecord.getDiagAccordName();
					if (diagCompareName.equals("门诊诊断与出院诊断")) {
						if (StringUtils.isEmpty(diagAccordName)) {
							this.addMedicalModify(ModifyConstant.NO_OUTPATIENT_DISCHARGE_DIAGNOSIS_OR_ISUNDO,
									medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NO_OUTPATIENT_DISCHARGE_DIAGNOSIS_OR_ISUNDO,
									"添加门诊诊断与出院诊断为:" + diagAccordName, medicalFunction.getId());
						}
					}
					if (diagCompareName.equals("入院诊断与出院诊断")) {
						if (StringUtils.isEmpty(diagAccordName)) {
							this.addMedicalModify(ModifyConstant.NO_HOSPITAL_DISCHARGE_DIAGNOSIS_OR_ISUNDO,
									medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.NO_HOSPITAL_DISCHARGE_DIAGNOSIS_OR_ISUNDO,
									"添加入院出院诊断为:" + diagAccordName, medicalFunction.getId());
						}
					}
					// 临床诊断与病理诊断
					if (diagCompareName.equals("临床诊断与病理诊断")) {
						if (StringUtils.isNotEmpty(diagAccordName)) {
							if (!diagAccordName.equals("未做") && pathologicDiagnosisCount == 0) {
								this.addMedicalModify(ModifyConstant.CLININAL_DIAGNOSIS_NOT_DONE,
										medicalFunction.getId());
							} else {
								this.updateMedicalModify(ModifyConstant.CLININAL_DIAGNOSIS_NOT_DONE,
										"无病理诊断名称时,临床与病理诊断符合选择为:" + diagAccordName, medicalFunction.getId());
							}
						}
						// 有病理诊断名称时,临床与病理诊断符合为空或者选择未做
						if (!clininalDiagnosisDone(diagAccordName, pathologicDiagnosisCount)) {
							this.addMedicalModify(ModifyConstant.CLININAL_DIAGNOSIS__DONE, medicalFunction.getId());
						} else {
							this.updateMedicalModify(ModifyConstant.CLININAL_DIAGNOSIS__DONE,
									"有病理诊断名称时,临床与病理诊断符合选择为:" + diagAccordName, medicalFunction.getId());
						}
					}

					// 术前诊断与术后诊断
					if (diagCompareName.equals("术前诊断与术后诊断")) {
						if (StringUtils.isNotEmpty(diagAccordName)) {
							if (!operationFlag && !diagAccordName.equals("未做")) {
								this.addMedicalModify(ModifyConstant.NO_OPERATION_CLININAL_AND_PATHOLOGICAL_IS_UNDO,
										medicalFunction.getId());
							} else {
								this.updateMedicalModify(ModifyConstant.NO_OPERATION_CLININAL_AND_PATHOLOGICAL_IS_UNDO,
										"无手术操作时,手术前后诊断符合情况选择为:" + diagAccordName, medicalFunction.getId());
							}
						}

					}

				}
			}

		}
	}

	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>> getMainDieaseAudit(MedicalSearchQuery
	// medicalSearchQuery) {
	// return medicalRecordAuditMapper.getMainDieaseAudit(medicalSearchQuery);
	// }

	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public int getMainDieaseAuditCount(MedicalSearchQuery medicalSearchQuery)
	// {
	// return
	// medicalRecordAuditMapper.getMainDieaseAuditCount(medicalSearchQuery);
	// }

	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// getApprovalDateBirthPage(MedicalSearchQuery medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.getApprovalDateBirthPage(medicalSearchQuery);
	// }

	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public long getApprovalDateBirthCount(MedicalSearchQuery
	// medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.getApprovalDateBirthCount(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// getHospitalFeesAuditPage(MedicalSearchQuery medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.getHospitalFeesAuditPage(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public long getHospitalFeesAuditCount(MedicalSearchQuery
	// medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.getHospitalFeesAuditCount(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// exportMedRecordInfoToExcel(MedicalSearchQuery medicalSearchQuery) {
	//
	// return
	// medicalRecordAuditMapper.exportMedRecordInfoToExcel(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// exportMainAuditToExcel(MedicalSearchQuery medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.exportMainAuditToExcel(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// exportInHospitalMoneyauditToExcel(MedicalSearchQuery medicalSearchQuery)
	// {
	// return
	// medicalRecordAuditMapper.exportInHospitalMoneyauditToExcel(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// exportDateofbirthAuditToExcel(MedicalSearchQuery medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.exportDateofbirthAuditToExcel(medicalSearchQuery);
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<Map<String, Object>>
	// exportMedFileReworkToExcel(MedicalSearchQuery medicalSearchQuery) {
	// return
	// medicalRecordAuditMapper.exportMedFileReworkToExcel(medicalSearchQuery);
	// }

	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<AuditDetail> getOperationAudit(AuditQuery auditQuery) throws
	// ParseException {
	// List<String> firstGuidList =
	// medicalRecordAuditMapper.getFirstGuidsByOutHospTime(auditQuery);
	// if (CollectionUtils.isEmpty(firstGuidList)) {
	// return null;
	// }
	//
	// List<AuditDetail> auditDetailList = new ArrayList<>();
	//
	// for (String firstGuid : firstGuidList) {
	// AuditErrorMsg auditErrorMsg = null;
	// AuditDetail auditDetail = new AuditDetail();
	// List<AuditErrorMsg> auditErrorMsgList = new ArrayList<>();
	// String filePath =
	// configProperties.getServer().getHospitalNoteJsonLocalPath()
	// + StringUtil.getLocalPath(firstGuid);
	// String fileName = firstGuid + ".json";
	// Map<String, Object> jsonMap = readLineFile(filePath, fileName);
	// if (MapUtils.isEmpty(jsonMap)) {
	// continue;
	// }
	//
	// // 入院日期
	// String inHospitalDateTime = null;
	// // 出院日期
	// String outHospitalDateTime = null;
	// // 确诊日期
	// String diagConfirmedDateTime = null;
	// @SuppressWarnings("unchecked")
	// Map<String, Object> basicInfoMap = (Map<String, Object>)
	// jsonMap.get("basicInfo");
	// if (MapUtils.isEmpty(basicInfoMap)) {
	// return null;
	// }
	//
	// // 姓名
	// if (basicInfoMap.get("patientName") != null) {
	// auditDetail.setPatientName((String) basicInfoMap.get("patientName"));
	//
	// }
	// // 住院次数
	// if (basicInfoMap.get("visitNumber") != null) {
	// auditDetail.setInHospitalTime((Integer) basicInfoMap.get("visitNumber"));
	// }
	//
	// if (basicInfoMap.get("mrId") != null) {
	// auditDetail.setMrId((String) basicInfoMap.get("mrId"));
	// }
	//
	// if (basicInfoMap.get("onlyId") != null) {
	// auditDetail.setOnlyId((String) basicInfoMap.get("onlyId"));
	// }
	//
	// // 入院日期
	// if (basicInfoMap.get("inHospitalDateTime") != null) {
	// inHospitalDateTime = (String) basicInfoMap.get("inHospitalDateTime");
	// }
	// // 出院日期
	// if (basicInfoMap.get("outHospitalDateTime") != null) {
	// outHospitalDateTime = (String) basicInfoMap.get("outHospitalDateTime");
	// }
	//
	// Map<String, Object> operateInfoMap = (Map<String, Object>)
	// jsonMap.get("operateInfo");
	// if (MapUtils.isEmpty(operateInfoMap)) {
	// continue;
	// }
	//
	// List<Map<String, Object>> operateRecords = (List<Map<String, Object>>)
	// operateInfoMap.get("operateRecords");
	// if (CollectionUtils.isEmpty(operateRecords)) {
	// continue;
	// }
	//
	// for (Map<String, Object> operateRecord : operateRecords) {
	// String operateEndDate = null;
	// String operateCode = null;
	// String operateName = null;
	// String incisionLevelCode = null;
	// String opsLevelCode = null;
	// String cicatrizeTypeCode = null;
	// System.out.println(operateRecord);
	// if (operateRecord.get("operateCode") != null) {
	// operateCode = (String) operateRecord.get("operateCode");
	// }
	// if (operateRecord.get("operateName") != null) {
	// operateName = (String) operateRecord.get("operateName");
	// }
	// if (operateRecord.get("incisionLevelCode") != null) {
	// incisionLevelCode = (String) operateRecord.get("incisionLevelCode");
	// }
	// if (operateRecord.get("opsLevelCode") != null) {
	// opsLevelCode = (String) operateRecord.get("opsLevelCode");
	// }
	// if (operateRecord.get("cicatrizeTypeCode") != null) {
	// cicatrizeTypeCode = (String) operateRecord.get("cicatrizeTypeCode");
	// }
	// if (operateRecord.get("operateEndDate") != null) {
	// operateEndDate = (String) operateRecord.get("operateEndDate");
	// if (StringUtils.isNotEmpty(inHospitalDateTime)) {
	// if (this.strToDate(operateEndDate).getTime() <
	// this.strToDate(inHospitalDateTime).getTime()) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("手术操作时间小于入院时间!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// }
	//
	// if (StringUtils.isNotEmpty(outHospitalDateTime)) {
	// if (this.strToDate(operateEndDate).getTime() >
	// this.strToDate(outHospitalDateTime).getTime()) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("手术操作时间大于出院时间!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// }
	// }
	// // 手术编码不为空,手术名称为空
	// if (StringUtils.isNotEmpty(operateCode) &&
	// StringUtils.isEmpty(operateName)) {
	//
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("填写了手术编码需填写手术信息!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// // 手术编码为空,手术名称不为空
	// if (StringUtils.isEmpty(operateCode) &&
	// StringUtils.isNotEmpty(operateName)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("填写了手术信息需填写手术操作编码!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// // 切口等级已填写，未填写手术级别
	// if (StringUtils.isNotEmpty(incisionLevelCode) &&
	// StringUtils.isEmpty(opsLevelCode)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("切口等级已填写，未填写手术级别!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// // 切口等级为0而切口愈合类别应该为空
	// if (StringUtils.isEmpty(incisionLevelCode) &&
	// StringUtils.isNotEmpty(cicatrizeTypeCode)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("切口等级为0而切口愈合类别应该为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// }
	//
	// if (CollectionUtils.isNotEmpty(auditErrorMsgList)) {
	// auditDetail.setAuditErrorMsgList(auditErrorMsgList);
	// auditDetailList.add(auditDetail);
	// }
	//
	// }
	// return auditDetailList;
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<AuditDetail> getMainDiagnosisAudit(AuditQuery auditQuery) {
	// List<String> firstGuidList =
	// medicalRecordAuditMapper.getFirstGuidsByOutHospTime(auditQuery);
	// if (CollectionUtils.isEmpty(firstGuidList)) {
	// return null;
	// }
	//
	// List<AuditDetail> auditDetailList = new ArrayList<>();
	//
	// for (String firstGuid : firstGuidList) {
	// AuditErrorMsg auditErrorMsg = null;
	// AuditDetail auditDetail = new AuditDetail();
	// List<AuditErrorMsg> auditErrorMsgList = new ArrayList<>();
	// String filePath =
	// configProperties.getServer().getHospitalNoteJsonLocalPath()
	// + StringUtil.getLocalPath(firstGuid);
	// String fileName = firstGuid + ".json";
	// Map<String, Object> jsonMap = readLineFile(filePath, fileName);
	// if (MapUtils.isEmpty(jsonMap)) {
	// continue;
	// }
	//
	// @SuppressWarnings("unchecked")
	// Map<String, Object> basicInfoMap = (Map<String, Object>)
	// jsonMap.get("basicInfo");
	// if (MapUtils.isEmpty(basicInfoMap)) {
	// return null;
	// }
	//
	// // 姓名
	// if (basicInfoMap.get("patientName") != null) {
	// auditDetail.setPatientName((String) basicInfoMap.get("patientName"));
	//
	// }
	// // 住院次数
	// if (basicInfoMap.get("visitNumber") != null) {
	// auditDetail.setInHospitalTime((Integer) basicInfoMap.get("visitNumber"));
	// }
	//
	// if (basicInfoMap.get("mrId") != null) {
	// auditDetail.setMrId((String) basicInfoMap.get("mrId"));
	// }
	//
	// if (basicInfoMap.get("onlyId") != null) {
	// auditDetail.setOnlyId((String) basicInfoMap.get("onlyId"));
	// }
	//
	// // 疾病诊断
	// @SuppressWarnings("unchecked")
	// Map<String, Object> diseaseDiagInfoMap = (Map<String, Object>)
	// jsonMap.get("diseaseDiagInfo");
	// if (MapUtils.isEmpty(diseaseDiagInfoMap)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("主要诊断为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// } else {
	// @SuppressWarnings("unchecked")
	// List<Map<String, Object>> diseaseDiagRecords = (List<Map<String,
	// Object>>) diseaseDiagInfoMap
	// .get("diseaseDiagRecords");
	// if (CollectionUtils.isEmpty(diseaseDiagRecords)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("主要诊断为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// } else {
	// // 主要诊断
	// String mainDiagnosisCode = null;
	//
	// // 存储其他诊断code集合
	// List<String> otherMainDiagnosisCodeList = new ArrayList<>();
	// int mainDiagnosisCount = 0;
	// for (Map<String, Object> diseaseDiagRecord : diseaseDiagRecords) {
	// String diagTypeName = (String) diseaseDiagRecord.get("diagTypeName");
	// String diseaseDiagCode = (String)
	// diseaseDiagRecord.get("diseaseDiagCode");
	// if (StringUtils.isEmpty(diagTypeName)) {
	// continue;
	// }
	// if (diagTypeName.equals("主要诊断")) {
	// mainDiagnosisCount++;
	// if (StringUtils.isEmpty(diseaseDiagCode)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("主要诊断编码为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// } else {
	// mainDiagnosisCode = diseaseDiagCode;
	// }
	// } else {
	// if (StringUtils.isNotEmpty(diseaseDiagCode)) {
	// otherMainDiagnosisCodeList.add(diseaseDiagCode);
	// }
	// }
	// }
	//
	// if (mainDiagnosisCount == 0) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("主要诊断为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// } else if (mainDiagnosisCount > 1) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("主要诊断重复!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// if (StringUtils.isNotEmpty(mainDiagnosisCode)) {
	//
	// if (CollectionUtils.isNotEmpty(otherMainDiagnosisCodeList)) {
	// if (otherMainDiagnosisCodeList.contains(mainDiagnosisCode)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("主要诊断和其他编码重复!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// }
	//
	// // 不能作为主要诊断编码
	// String[] noDiagnosisCodeArrary = Constant.NO_MAIN_DIAGNOSIS_CODE;
	// if (ArrayUtils.contains(noDiagnosisCodeArrary, mainDiagnosisCode)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg(mainDiagnosisCode + "不能作为主要诊断!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// // 可能产生医疗隐患的主要诊断编码
	// String[] medicalTangleDiagnosisCodeArrary =
	// Constant.MEDICAL_TANGLE_MAIN_DIAGNOSIS_CODE;
	// if (ArrayUtils.contains(medicalTangleDiagnosisCodeArrary,
	// mainDiagnosisCode)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg(mainDiagnosisCode + "作为主要诊断可能产生医患纠纷!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// // V、W、y、X编码不能作为主要诊断
	// if (StringUtils.startsWithAny(mainDiagnosisCode, "V", "W", "y", "X")) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("V、W、y、X编码不能作为主要诊断!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// }
	// }
	// }
	//
	// if (CollectionUtils.isNotEmpty(auditErrorMsgList)) {
	// auditDetail.setAuditErrorMsgList(auditErrorMsgList);
	// auditDetailList.add(auditDetail);
	// }
	//
	// }
	// return auditDetailList;
	// }
	//
	// @Transactional(readOnly = true)
	// @TargetDataSource(name = "ds1")
	// @Override
	// public List<AuditDetail> getMedDateAuditList(AuditQuery auditQuery)
	// throws ParseException {
	// List<String> firstGuidList =
	// medicalRecordAuditMapper.getFirstGuidsByOutHospTime(auditQuery);
	// if (CollectionUtils.isEmpty(firstGuidList)) {
	// return null;
	// }
	//
	// List<AuditDetail> auditDetailList = new ArrayList<>();
	//
	// for (String firstGuid : firstGuidList) {
	// AuditErrorMsg auditErrorMsg = null;
	// AuditDetail auditDetail = new AuditDetail();
	// List<AuditErrorMsg> auditErrorMsgList = new ArrayList<>();
	// String filePath =
	// configProperties.getServer().getHospitalNoteJsonLocalPath()
	// + StringUtil.getLocalPath(firstGuid);
	// String fileName = firstGuid + ".json";
	// Map<String, Object> jsonMap = readLineFile(filePath, fileName);
	// if (MapUtils.isEmpty(jsonMap)) {
	// continue;
	// }
	//
	// // 入院日期
	// String inHospitalDateTime = null;
	// // 出院日期
	// String outHospitalDateTime = null;
	// // 确诊日期
	// String diagConfirmedDateTime = null;
	// @SuppressWarnings("unchecked")
	// Map<String, Object> basicInfoMap = (Map<String, Object>)
	// jsonMap.get("basicInfo");
	// if (MapUtils.isEmpty(basicInfoMap)) {
	// return null;
	// }
	//
	// // 姓名
	// if (basicInfoMap.get("patientName") != null) {
	// auditDetail.setPatientName((String) basicInfoMap.get("patientName"));
	//
	// }
	// // 住院次数
	// if (basicInfoMap.get("visitNumber") != null) {
	// auditDetail.setInHospitalTime((Integer) basicInfoMap.get("visitNumber"));
	// }
	//
	// if (basicInfoMap.get("mrId") != null) {
	// auditDetail.setMrId((String) basicInfoMap.get("mrId"));
	// }
	//
	// if (basicInfoMap.get("onlyId") != null) {
	// auditDetail.setOnlyId((String) basicInfoMap.get("onlyId"));
	// }
	//
	// // 入院日期
	// if (basicInfoMap.get("inHospitalDateTime") != null) {
	// inHospitalDateTime = (String) basicInfoMap.get("inHospitalDateTime");
	// } else {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("入院日期为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// // 出院日期
	// if (basicInfoMap.get("outHospitalDateTime") != null) {
	// outHospitalDateTime = (String) basicInfoMap.get("outHospitalDateTime");
	// } else {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("出院日期为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// // 确诊时间
	// if (basicInfoMap.get("diagConfirmedDateTime") != null) {
	// diagConfirmedDateTime = (String)
	// basicInfoMap.get("diagConfirmedDateTime");
	// } else {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("确诊日期为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// if (StringUtils.isNotEmpty(inHospitalDateTime) &&
	// StringUtils.isNoneEmpty(outHospitalDateTime)) {
	// if (this.strToDate(inHospitalDateTime).getTime() >
	// this.strToDate(outHospitalDateTime).getTime()) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("入院时间大于出院时间!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// if (StringUtils.isNotEmpty(diagConfirmedDateTime)) {
	// if (this.strToDate(inHospitalDateTime).getTime() >
	// this.strToDate(diagConfirmedDateTime)
	// .getTime()) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("确诊日期小于入院时间!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	//
	// if (this.strToDate(outHospitalDateTime).getTime() <
	// this.strToDate(diagConfirmedDateTime)
	// .getTime()) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("确诊日期大于出院时间!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// }
	// }
	//
	// String qualityControlDateTime = null;
	//
	// @SuppressWarnings("unchecked")
	// Map<String, Object> cureInfoMap = (Map<String, Object>)
	// jsonMap.get("cureInfo");
	// if (MapUtils.isNotEmpty(cureInfoMap)) {
	// qualityControlDateTime = (String)
	// cureInfoMap.get("qualityControlDateTime");
	//
	// if (StringUtils.isEmpty(qualityControlDateTime)) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("质控时间为空!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// } else {
	// if (StringUtils.isNoneEmpty(inHospitalDateTime)) {
	// if (this.strToDate(inHospitalDateTime).getTime() >
	// this.strToDate(qualityControlDateTime)
	// .getTime()) {
	// auditErrorMsg = new AuditErrorMsg();
	// auditErrorMsg.setErrorMsg("质控日期小于入院时间!");
	// auditErrorMsg.setErrorType(ErrorType.CLINICIAN);
	// auditErrorMsgList.add(auditErrorMsg);
	// }
	// }
	// }
	// }
	//
	// if (CollectionUtils.isNotEmpty(auditErrorMsgList)) {
	// auditDetail.setAuditErrorMsgList(auditErrorMsgList);
	// auditDetailList.add(auditDetail);
	// }
	//
	// }
	// return auditDetailList;
	// }

	@Transactional(readOnly = true)
	@TargetDataSource(name = "ds1")
	public List<String> getFirstGuidList(MedRecordQuery medRecordQuery) {
		return medicalRecordAuditMapper.ajaxQualityEvaluationPage(medRecordQuery);
	}

	@SuppressWarnings("unchecked")
	public Map<String, Object> readLineFile(String filePath, String fileName) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();

		try {
			File destFile = new File(filePath, fileName);
			String jsonStr = null;
			if (destFile.exists()) {
				// FileReader fr = new FileReader(destFile);
				BufferedReader br = new BufferedReader(
						new InputStreamReader(new FileInputStream(filePath + fileName), "UTF-8"));
				jsonStr = br.readLine();
				jsonMap = JsonUtils.jsonToPojo(jsonStr, Map.class);

			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return jsonMap;
	}

	public Date strToDate(String date) throws ParseException {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return dateFormat.parse(date);
	}

	/**
	 * 拼装hospitalNote
	 * 
	 * @param firstGuid
	 * @param basicInfoMap
	 * @return
	 */
	public HospitalNote appendHospitalNote(String firstGuid, Map<String, Object> basicInfoMap) {
		HospitalNote hospitalNote = new HospitalNote();
		hospitalNote.setFirstGuid(firstGuid);
		hospitalNote.setName(basicInfoMap.get("patientName") == null ? null : (String) basicInfoMap.get("patientName"));
		hospitalNote.setCreateDate(new Date());
		hospitalNote.setMrId(basicInfoMap.get("mrId") == null ? null : (String) basicInfoMap.get("mrId"));
		hospitalNote.setOnlyId(basicInfoMap.get("onlyId") == null ? null : (String) basicInfoMap.get("onlyId"));
		hospitalNote.setIdNumber(basicInfoMap.get("idNumber") == null ? null : (String) basicInfoMap.get("idNumber"));
		hospitalNote.setVisitNumber(basicInfoMap.get("visitNumber")==null?null:(Integer)basicInfoMap.get("visitNumber"));
		hospitalNote.setOutHospitalOfficeCode(
				basicInfoMap.get("outDeptCode") == null ? null : (String) basicInfoMap.get("outDeptCode"));
		hospitalNote.setOutHospitalOfficeName(
				basicInfoMap.get("outDeptName") == null ? null : (String) basicInfoMap.get("outDeptName"));
		hospitalNote.setOutHospitalTypeCode(basicInfoMap.get("outHospitalTypeCode") == null ? null
				: (String) basicInfoMap.get("outHospitalTypeCode"));
		hospitalNote.setOutHospitalType(basicInfoMap.get("outHospitalTypeName") == null ? null
				: (String) basicInfoMap.get("outHospitalTypeName"));
		hospitalNote.setBirthday(basicInfoMap.get("birthday") == null ? null
				: DateUtil.strToDate((String) basicInfoMap.get("birthday")));
		hospitalNote.setOutHospitalDate(basicInfoMap.get("outHospitalDateTime") == null ? null
				: DateUtil.strToDate((String) basicInfoMap.get("outHospitalDateTime")));
		return hospitalNote;
	}

	/**
	 * 拼装更新hospitalNote
	 * 
	 * @param firstGuid
	 * @param basicInfoMap
	 * @return
	 */
	public HospitalNote appendUpdateHospitalNote(String firstGuid, Map<String, Object> basicInfoMap,
			HospitalNote hospitalNote) {
		hospitalNote.setFirstGuid(firstGuid);
		hospitalNote.setName(basicInfoMap.get("patientName") == null ? hospitalNote.getName()
				: (String) basicInfoMap.get("patientName"));
		hospitalNote.setCreateDate(new Date());
		hospitalNote
				.setMrId(basicInfoMap.get("mrId") == null ? hospitalNote.getMrId() : (String) basicInfoMap.get("mrId"));
		hospitalNote.setOnlyId(
				basicInfoMap.get("onlyId") == null ? hospitalNote.getOnlyId() : (String) basicInfoMap.get("onlyId"));
		hospitalNote.setIdNumber(basicInfoMap.get("idNumber") == null ? hospitalNote.getIdNumber()
				: (String) basicInfoMap.get("idNumber"));
		hospitalNote.setVisitNumber(basicInfoMap.get("visitNumber")==null?null:(Integer)basicInfoMap.get("visitNumber"));
		hospitalNote.setOutHospitalOfficeCode(basicInfoMap.get("outDeptCode") == null
				? hospitalNote.getOutHospitalOfficeCode() : (String) basicInfoMap.get("outDeptCode"));
		hospitalNote.setOutHospitalOfficeName(basicInfoMap.get("outDeptName") == null
				? hospitalNote.getOutHospitalOfficeName() : (String) basicInfoMap.get("outDeptName"));
		hospitalNote.setOutHospitalTypeCode(basicInfoMap.get("outHospitalTypeCode") == null
				? hospitalNote.getOutHospitalTypeCode() : (String) basicInfoMap.get("outHospitalTypeCode"));
		hospitalNote.setOutHospitalType(basicInfoMap.get("outHospitalTypeName") == null
				? hospitalNote.getOutHospitalType() : (String) basicInfoMap.get("outHospitalTypeName"));
		hospitalNote.setBirthday(basicInfoMap.get("birthday") == null ? hospitalNote.getBirthday()
				: DateUtil.strToDate((String) basicInfoMap.get("birthday")));
		hospitalNote
				.setOutHospitalDate(basicInfoMap.get("outHospitalDateTime") == null ? hospitalNote.getOutHospitalDate()
						: DateUtil.strToDate((String) basicInfoMap.get("outHospitalDateTime")));
		return hospitalNote;
	}

	// 判断质控时间是否为空
	public boolean diagConfirmTimeIsNull(Date diagContolTime, Date inHospitalDate, Date outHospitalDate) {
		boolean flag = false;
		// 质控时间为空
		if (diagContolTime == null) {
			return flag;
		} else {
			// 质控时间小于入院时间
			if ((inHospitalDate != null && diagContolTime.getTime() < inHospitalDate.getTime())
					|| (outHospitalDate != null && diagContolTime.getTime() > outHospitalDate.getTime())) {
				return flag;
			} else {
				return true;
			}
		}
	}

	/**
	 * 判断质控时间是否为空
	 * 
	 * @return
	 */
	public boolean qualityControlDateIsNull(Date qualityControlDate, Date inHospitalDate) {
		boolean flag = false;
		if (qualityControlDate == null) {
			return flag;
		} else {
			if (inHospitalDate != null && qualityControlDate.getTime() < inHospitalDate.getTime()) {
				return flag;
			} else {
				return true;
			}
		}
	}

	// 病案质量未录入或不是"甲级病案","乙级病案","丙级病案"!
	public boolean qualityRecordNameIsNull(String medicalRecordQualityName) {
		boolean flag = false;
		if (StringUtils.isEmpty(medicalRecordQualityName)) {
			return flag;
		} else {
			if (medicalRecordQualityName.equals("甲") || medicalRecordQualityName.equals("乙")
					|| medicalRecordQualityName.equals("丙")) {
				return true;
			}
			return flag;
		}
	}

	/**
	 * 新增MedicalModify
	 * 
	 * @param modifyCode
	 * @param medicalFunctionId
	 */
	public void addMedicalModify(String modifyCode, Integer medicalFunctionId) {
		MedModifyVo medModifyVo = medicalModifyMapper
				.getMedicalModifyByMedicalFunctionAndMedErrorCode(medicalFunctionId, modifyCode);
		if (medModifyVo != null) {
			MedicalModify medicalModify = new MedicalModify();
			medicalModify.setId(medModifyVo.getMedicalModifyId());
			medicalModify.setStatus(ModifyConstant.UN_MODIFY);
			medicalModify.setMedicalReviseContent(null);
			medicalModify.setMedicalErrorId(medModifyVo.getModifyErrorId());
			medicalModify.setMedicalFunctionId(medicalFunctionId);
			medicalModify.setUpdateTime(new Date());
			medicalModifyMapper.updateByPrimaryKey(medicalModify);
			return;
		}
		MedicalModify medicalModify = new MedicalModify();
		int medicalErrorId = medicalErrorMapper.getMedicalErrorIdByCode(modifyCode);
		medicalModify.setMedicalErrorId(medicalErrorId);
		medicalModify.setMedicalFunctionId(medicalFunctionId);
		medicalModify.setStatus(ModifyConstant.UN_MODIFY);
		medicalModifyMapper.insertSelective(medicalModify);
	}

	/**
	 * 更新MedicalModify
	 * 
	 * @param modifyCode
	 * @param modifyContent
	 * @param medicalFunctionId
	 */
	public void updateMedicalModify(String modifyCode, String modifyContent, Integer medicalFunctionId) {
		MedModifyVo medModifyVo = medicalModifyMapper
				.getMedicalModifyByMedicalFunctionAndMedErrorCode(medicalFunctionId, modifyCode);
		if (medModifyVo == null) {
			return;
		}
		if (medModifyVo.getMedicalModifyStatus() == ModifyConstant.UN_MODIFY) {
			MedicalModify medicalModify = new MedicalModify();
			medicalModify.setId(medModifyVo.getMedicalModifyId());
			medicalModify.setStatus(ModifyConstant.MODIFIED);
			medicalModify.setMedicalReviseContent(modifyContent);
			medicalModify.setMedicalFunctionId(medicalFunctionId);
			medicalModify.setUpdateTime(new Date());
			medicalModifyMapper.updateByPrimaryKeySelective(medicalModify);
		}

	}

	/**
	 * 治疗结果是否有和出院方式一致
	 * 
	 * @param outTypeName
	 *            出院方式
	 * @param treateResult
	 *            治疗结果
	 * @return
	 */
	public boolean treatemnetResutIsMatchOutTypeName(String outTypeName, String treateResult) {
		boolean flag = true;
		if (StringUtils.isNotEmpty(outTypeName)) {
			if ((outTypeName.equals("死亡") && treateResult.equals("治愈"))
					|| (outTypeName.equals("死亡") && treateResult.equals("好转"))
					|| (outTypeName.equals("正常") && treateResult.equals("死亡"))) {
				flag = false;
			} else {
				flag = true;
			}
		}
		return flag;

	}

	/**
	 * 有病理诊断名称时,临床与病理诊断符合为空或者选择未做
	 * 
	 * @param diagAccordName
	 *            临床与病理诊断
	 * @param pathologicDiagnosisCount
	 *            病理诊断
	 * @return
	 */
	public boolean clininalDiagnosisDone(String diagAccordName, int pathologicDiagnosisCount) {
		boolean flag = true;
		if ((StringUtils.isEmpty(diagAccordName) && pathologicDiagnosisCount > 0)
				|| ((StringUtils.isNotEmpty(diagAccordName) && diagAccordName.equals("未做")
						&& pathologicDiagnosisCount > 0))) {
			flag = false;
		}
		return flag;
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void manualAddMedicalModify(AuditQuery auditQuery) {
		if (auditQuery == null) {
			return;
		}
		String firstGuid = auditQuery.getFirstGuid();
		List<AuditError> auditErrorList = auditQuery.getAuditErrorList();
		if (CollectionUtils.isEmpty(auditErrorList)) {
			return;
		}
		;

		MedicalFunction medicalFunction = new MedicalFunction();
		if (medicalFunctionMapper.isExistMedFunctionByFirstGuidAndFunType(firstGuid, FunctionType.MEDICAL_MODIFY) > 0) {
			medicalFunction = medicalFunctionMapper.getMediFunctionIdFirstGuidAndFunType(firstGuid,
					FunctionType.MEDICAL_MODIFY);
		} else {
			medicalFunction.setFunctionTypeId(FunctionType.MEDICAL_MODIFY);
			medicalFunction.setCreateTime(new Date());
			medicalFunction.setFirstGuid(firstGuid);
			medicalFunction.setStatus(1);
			medicalFunctionMapper.insertSelective(medicalFunction);
		}

		for (AuditError auditError : auditErrorList) {
			this.addMedicalModify(auditError.getMedicalErrorId(), medicalFunction.getId());
		}

	}

	@Transactional(readOnly = true)
	@Override
	public List<Map<String, Object>> getMedicalErrorByFirstGuid(String firstGuid) {

		return medicalModifyMapper.getMedicalErrorByFirstGuid(firstGuid);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void deleteMedicalModify(Integer medicalErrorId) {

		medicalModifyMapper.deleteByPrimaryKey(medicalErrorId);
	}

	@Transactional(readOnly = true)
	@Override
	public List<String> getMedicalModifyFirstGuidList(AuditQuery auditQuery) {

		return medicalModifyMapper.getMedicalModifyFirstGuidList(auditQuery);
	}

	/**
	 * 病案返修查询
	 */
	@Transactional(readOnly = true)
	@Override
	public Map<String, Object> getMedicalAuditErrorList(MedRecordQuery medRecordQuery) {
		Map<String, Object> map = new HashMap<>();
		// 查询出所有修改或者未修改返修的病案
		List<Map<String, Object>> modifyMapList = new ArrayList<>();
		int totalCount = 0;

		// if (auditQuery.getStatus() == 1) {
		modifyMapList = medicalModifyMapper.getMedicalModifyList(medRecordQuery);
		totalCount = medicalModifyMapper.getMedicalModifyListCount(medRecordQuery);
		// } else {
		// modifyMapList =
		// medicalModifyMapper.getMedicalModifyUpdatedList(auditQuery);
		// totalCount =
		// medicalModifyMapper.getMedicalModifyUpdatedCount(auditQuery);
		// }

		// 查询某份病案对应的所有的返修记录
		for (Map<String, Object> modifyMap : modifyMapList) {

			if (MapUtils.isEmpty(modifyMap)) {
				continue;
			}

			// System.out.println(modifyMap);
			Integer medicalFunctionId = (Integer) modifyMap.get("medicalFunctionId");

			List<Map<String, Object>> medicalErrorList = null;

			// if (auditQuery.getStatus() == 1) {
			// //只要有一条是未返修改的都算是未修改的
			// medicalErrorList =
			// medicalModifyMapper.getMedicalErrorList(medicalFunctionId, null);
			// } else {
			medicalErrorList = medicalModifyMapper.getMedicalErrorList(medicalFunctionId, 1);
			// }

			modifyMap.put("medicalErrorList", medicalErrorList);
			modifyMap.put("medicalErrorLength", medicalErrorList.size());
		}

		map.put("modifyMapList", modifyMapList);
		map.put("totalCount", totalCount);
		System.out.println(map);
		return map;
	}

	// /**
	// * 病案返修查询
	// */
	// @Transactional(readOnly = true)
	// @Override
	// public Map<String, Object> getMedicalAuditErrorList(AuditQuery
	// auditQuery) {
	// Map<String, Object> map = new HashMap<>();
	// //查询出所有修改或者未修改返修的病案
	// List<Map<String, Object>> modifyMapList = null;
	// int totalCount = 0;
	//
	// if (auditQuery.getStatus() == 1) {
	// modifyMapList = medicalModifyMapper.getMedicalModifyList(auditQuery);
	// totalCount = medicalModifyMapper.getMedicalModifyListCount(auditQuery);
	// } else {
	// modifyMapList =
	// medicalModifyMapper.getMedicalModifyUpdatedList(auditQuery);
	// totalCount =
	// medicalModifyMapper.getMedicalModifyUpdatedCount(auditQuery);
	// }
	//
	// //查询某份病案对应的所有的返修记录
	// for (Map<String, Object> modifyMap : modifyMapList) {
	//
	// if (MapUtils.isEmpty(modifyMap)) {
	// continue;
	// }
	//
	// System.out.println(modifyMap);
	// Integer medicalFunctionId = (Integer) modifyMap.get("medicalFunctionId");
	//
	// List<Map<String, Object>> medicalErrorList = null;
	//
	// if (auditQuery.getStatus() == 1) {
	// //只要有一条是未返修改的都算是未修改的
	// medicalErrorList =
	// medicalModifyMapper.getMedicalErrorList(medicalFunctionId, null);
	// } else {
	// medicalErrorList =
	// medicalModifyMapper.getMedicalErrorList(medicalFunctionId,
	// auditQuery.getStatus());
	// }
	//
	// modifyMap.put("medicalErrorList", medicalErrorList);
	// modifyMap.put("medicalErrorLength", medicalErrorList.size());
	// }
	//
	//
	// map.put("modifyMapList", modifyMapList);
	// map.put("totalCount", totalCount);
	// System.out.println(map);
	// return map;
	// }

}
